package com.liangwj.springbootdesignpatterns.createTypePatterns.ProtoType;

import java.util.ArrayList;
import java.util.List;

/**
 * <b>Description:</b> 原型模式的调用类 <br/>
 * @author Lingwenjun
 * @date 2019/1/22-18:13
 * @version 1.0
 */
public class PrototypeDemoTest {

    public static void main(String[] args) {

        // 先创建一个EmailObject原型, 用来被复制
        EmailObject emailObject = new EmailObject("title", "context");

        //客户对象, 接收邮件
        final BenzEmailClient emailClient = new BenzEmailClient();

        //原本正常写法
        emailClient.getEmailList().forEach((s) -> {
            EmailObject email = new EmailObject("title", "context");
            email.setReceiver(s);
            emailClient.sendEmail(email);
        });

        //使用 原型设计模式 写法, 给所有用户发送邮件
        emailClient.getEmailList().forEach((string) -> {
            //根据对象复制新的对象
            EmailObject copyEmail = emailObject.clone();
            //获取集合中的收件人
            copyEmail.setReceiver(string);
            emailClient.sendEmail(copyEmail);
        });


    }
}
